#include <bits/stdc++.h>
using namespace std;
const int N=200005;
int T;
int a[N];
int n;
long long ans;
bool cmp(int a,int b)
{
    return a<b;
}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    for (int i=1;i<=T;i++)
    {
        cin>>n;
        for (int j=1;j<=n;j++)
        {
            cin>>a[j];
        }
        sort(a+1,a+n+1,cmp);
        for (int j=1;j<n;j++)
        {
            if (a[j]==a[j+1])
            {
                ans+=a[j+1];
            }
        }
        cout<<ans<<endl;
        ans=0;
    }

    return 0;
}
